﻿/**
* Build a data structure on an XML file. 
*/

class utils.XMLDataBuilder
{
	static public function build( node:XMLNode ):Object{
		var obj = new Object();
		// parsing properties
		obj._attr = new Object();
		for ( var attr in node.attributes )	{
			obj._attr[attr] = node.attributes[attr];
		}
		
		// parsing childnodes.
		for ( var i=0; i<node.childNodes.length; i++ ) {
			var cn = node.childNodes[i];
			if ( cn.nodeType == 1 ){
				if ( !obj[cn.nodeName] )
				{
					obj[cn.nodeName] = new Array();
				}
				obj[cn.nodeName].push(XMLDataBuilder.build( cn ));
			}
			else if ( cn.nodeType == 3 ){
				obj._value = cn.nodeValue;
			}
		}

		return obj;
	}	
}